﻿<!--#include Virtual="../config.asp"-->
<!--#include Virtual="/public_sub.asp"-->
<!--#include Virtual="/public_ads.asp"-->
<%
var pagetitles = [],
pagename = "news_read";
newsid = t_cint(request("newsid")),
page = request("page").toLowerCase(),
classurl = request("classurl").toLowerCase(),
cachefile = '';
if(isMobile && isShowSlider()){
	cachefile = "/cache/newscontent/"+newsid%100+"/m_"+newsid;
}else{
	cachefile = "/cache/newscontent/"+newsid%100+"/"+newsid;
}

Rs = ExecSql("select news.*,news_content,isnull(cartoon_id,0) as mhid,isnull(cartoon_name,'') as mhname from news with(nolock) left join news_content with(nolock) on news.id=news_content.id left join cartoon with(nolock) on cartoon_id=dbo.fn_mhidFromList(mhid_list) where news.id="+newsid+" and status=1");
news = Rs2Json(Rs);

if(news.length==0||classurl=="xiaoshuo"){
	WriteErr("无法找到该记录，可能已被删除！",404);
} else news = news[0];

if(news.class_urlid!=classurl) Redirect("/news/"+news.class_urlid+"/"+newsid+".html",301);//记录被修改了栏目后要做301转向

news.sourcename = news.sourcename || "网络";
news.author = news.author || "未知";
news.href = "http://www."+__config.domain+"/news/"+classurl+"/"+newsid+".html";//本页面访问地址，用于版权信息


//获得全部分页标题
if(news.news_content.indexOf('id="p" name="p"')!=-1){
	var pagecontents = news.news_content.split('<a class="newspage" id="p" name="p">');//将内容切割为数组，元素0为空，元素n为第n页内容
	news.news_content = "";

	foreach(pagecontents,function(i,v){
		pagetitles.push(v.left(v.indexOf("</a>")));
		if(page=="all" && i) news.news_content += '<a class="newspage" id="p'+i+'" name="p'+i+'">第'+i+'页：'+v;
	});
	//页码容错
	if(page=="") page=1;//有分页时默认第一页
	else if(t_cint(page)>=pagetitles.length) page=pagetitles.length-1;

	if(page!="all") news.news_content = '<a class="newspage" id="p" name="p">第'+page+'页：'+pagecontents[page];
}else{
	page = 0;
}

if(t_cint(page)==0) cachefile += ".txt";//无分页或page为all时
else cachefile += "_"+page+".txt";//有分页且页码不为all

// 内容中的图片路径处理、关键词库替换
//news.news_content = replaceKeyLink(news.news_content);

function loadCacheNews(filepath){
		var truefile = Server.MapPath(filepath);
		var fso=new ActiveXObject("Scripting.FileSystemObject");
		if(fso.FileExists(truefile) && fso.GetFile(truefile).size>0){//文件存在且大于0字节
			Server.Execute(filepath);
		}else{//否则执行关键词替换并重写缓存
			if(isMobile && isShowSlider()){
			  news.news_content = installPicData(replaceKeyLink(news.news_content));
			}else{
			  news.news_content = replaceKeyLink(news.news_content);
			}
			Write(news.news_content);
			AdoWriteFile(filepath, news.news_content);
		}
		fso=null;
}

function installPicData(str){
	
	str = str.replace(/[\f\n\r\t\v]|<(.+)>(\s+|&nbsp;+)<\/\1>/g,'');
	
	var imgArr = str.match(/<img\s+.*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/ig);
	var arr = str.split(/<img\s+.*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/ig);
	
	var strArr = [];
	var len = arr.length;

	for(var i=0; i<len; i++){
	  var match = arr[i].match(/<(.+)(\s.*)?>.*<\/\1>/g);
	  //if(match){
		strArr.push(match)
	  //}
	}
	var tmpArr = [];
	var imgLen = imgArr.length;
	var strLen = strArr.length;
	for(var k=0; k < imgLen ; k++){
	  var con = '';
	  if(k===0){
		con = (strArr[0]?strArr[0]:'') + (strArr[1]?strArr[1]:'');
	  }else{
		con = (strArr[k+1]?strArr[k+1]:'');
	  }
	  tmpArr[k] = {
			img: '<img class="swiper-lazy" ' + imgArr[k].match(/src=(\'|\")([^(\'|\")]*?)\1/ig)[0] + ' />',
			con: con
		}
	}
	
	var len = tmpArr.length;
	var tempStr = '';
	for(var i=0; i<len; i++){
		tempStr+= '<li class="swiper-slide"><div class="swiper-zoom-container">'+tmpArr[i].img+'<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div></div>';
		if(tmpArr[i].con){
		tempStr+='<div class="desc"><div class="scrollBox">'+tmpArr[i].con+'</div></div>';
		}
		tempStr+='</li>'
	}
	
	return tempStr;
}
function isShowSlider(){
 var type = ['haibao','bizhi','cosplay','meinv','shouban','sige'];
 var isFlag = false;
 for(var key in type){
	if(type[key] === classurl) isFlag = true
 }
 return isFlag;
}


var sqlprefix = "",
sqlstr = "",
mhIDs = [],//相关漫画ID
crumb = [],//面包屑
tags = [],//标签（关键词）
rightData = [],
relatenews = [],//相关资讯
allchapter = [],//全部章节（资源类）
relatecomics = [],//相关漫画
notin = [news.id],//相关内容中要排除的newsid
islianzai = __lianzaiclass.join().indexOf(classurl)!=-1,//是否连载型资源(动画、电视剧、小说、有声小说)
danwei = "篇",
sort = __types[2][classurl],//当前记录的栏目信息
father = __types[2][sort.father] || [];//当前栏目的父栏目信息

//关联漫画ID列表
if(t_cstr(news.mhid_list) && news.mhid_list.length>2) mhIDs = news.mhid_list.substring(1,news.mhid_list.length-1).split(",");
//news标签列表
if(t_cstr(news.keyword) && news.keyword.length>2) tags = news.keyword.substring(1,news.keyword.length-1).split(",");


/* 相关漫画 开始 */
if(mhIDs.length){
	Rs = ExecSql("select cartoon_id,cartoon_name,latest_cartoon_topic_name from cartoon with(nolock) where cartoon_id in ("+mhIDs+") and show_type in (1,"+__config.siteid+")");
	relatecomics = Rs2Json(Rs);
}
/* 相关漫画 结束 */


/* 右侧边栏数据 开始 */
siblings = father.son||[classurl];//当前栏目及其兄弟栏目数组
siblings.splice(inArray(classurl, siblings),1);//将当前分类移动到兄弟栏目最前面
siblings.unshift(classurl);//不能合并为一行，因为splice方法返回的是被删除的元素

if(classurl=="ziliao") siblings = [classurl].concat(__types[2]["renwu"].son);//资料库和人物都归类为百科
foreach(siblings,function(i,v){
	sqlstr += "select top 9 id,title,class_urlid,createtime from news with(nolock) where class_urlid='"+v+"' and status=1 order by id desc "
});
Rs = ExecSql(sqlstr);
foreach(siblings,function(i,v){
	rightData[i] = Rs2Json(Rs);
	Rs = Rs.NextRecordset;
});
/* 右侧边栏数据 结束 */


/* 底部相关内容 开始 */
if(islianzai){//章节目录（仅连载型资源才有）
	Rs = ExecSql("select id,title,groupname from news with(nolock) where class_urlid='"+classurl+"' and mhid_list = '"+news.mhid_list+"' and status=1 order by ordernum desc,id desc");
	allchapter = Rs2Json(Rs);
	danwei = (classurl=="donghua"||classurl=="dianshi")?"集":"章"
}else if(classurl=="ziliao"){//全部资料库
	Rs = ExecSql("select id,title,groupname from news with(nolock) where class_urlid='"+classurl+"' and mhid_list = '"+news.mhid_list+"' and status=1 order by groupname desc,id desc");
	allchapter = Rs2Json(Rs);
} else {
	var count = 10;//需要取多少条记录
	if(sort.father=="renwu") count=12;//人物类型显示12条记录;

	if(mhIDs.length){//取相同漫画ID下的同父栏目记录
		Rs = ExecSql("select top "+count+" id,title,class_urlid,createtime from news with(nolock) where status=1 and id<>"+notin[0]+" and (mhid_list like '%,"+mhIDs.join(",%' or mhid_list like '%,")+",%') and class_urlid in ('"+siblings.join("','")+"')");
		relatenews = Rs2Json(Rs);
	}
	if(relatenews.length<count && tags.length){//小于10条记录时用标签关联查询
		foreach(relatenews,function(i,v){ notin[i+1]=v.id });
		Rs = ExecSql("select top "+(count-relatenews.length)+" id,title,class_urlid,createtime from news with(nolock) where status=1 and id not in ("+notin+") and (keyword like '%,"+tags.join(",%' or keyword like '%,")+",%') and class_urlid in ('"+siblings.join("','")+"')");
		relatenews = relatenews.concat(Rs2Json(Rs));
	}
	if(relatenews.length<count){//如果还小于10条记录则取同父栏目记录补充
		foreach(relatenews,function(i,v){ notin[i+1]=v.id });
		Rs = ExecSql("select top "+(count-relatenews.length)+" id,title,class_urlid,createtime from news with(nolock) where status=1 and id not in ("+notin+") and class_urlid in ('"+siblings.join("','")+"') order by id desc");
		relatenews = relatenews.concat(Rs2Json(Rs));
	}
}
/* 底部相关内容 结束 */

/* SEO信息处理 开始 */
if(islianzai && news.mhname){
	var title = news.title.replace(news.mhname+" ","");//替换为第XX集格式
	news.title = news.mhname+title;
	news.summary = news.mhname+sort.name+title+"由"+__config.sitename+"收集整理自"+news.sourcename+"，"+__config.sitename+"为您第一时间更新"+news.mhname+sort.name+"，看"+news.mhname+sort.name+"就上"+__config.sitename;
	//斗罗大陆第20集 斗罗大陆动画第20集
	if(news.title.byteLength()<25) news.title += " "+news.mhname+sort.name+title;
}else if(sort.father=="renwu"){
	if(news.mhname){
		var title = news.title.replace(news.mhname,"").trim();
		news.title = title+" "+news.mhname+title;//琉星 偷星九月天琉星 偷星九月天角色琉星
		if(news.title.byteLength()<25) news.title += " "+news.mhname+sort.name+title;
	}else
		news.title += " "+sort.name+news.title+"简介";
}else if(sort.father!="zixun" && news.mhname){
	news.title = news.mhname+(news.groupname||sort.name)+" "+news.title;//只要是关联了漫画ID的，都在标题前面加上漫画名及当前栏目名
}else{
	//if(news.title.byteLength()<25) news.title = news.mhname+sort.name+news.groupname+" "+news.title;
}
//摘要为空取内容前200个字节，内容为空取标题
news.summary = news.summary.trim() || news.news_content.FilterHtml().left(200).trim() || news.title;
if(sort.father=="tupian")news.summary+="。请点击图片查看大图，右键图片选“图片另存为”可以下载图片！";
seo = {
	title : news.title + " " + __config.sitename,
	key : tags.join() || news.title.replace(/ /g,","),
	desc : news.summary.left(80)
};
/* SEO信息处理 结束 */


// 下一条和上一条
Rs = ExecSql("\
	select top 1 id,title,class_urlid from news with(nolock) where class_urlid='"+classurl+"' and status=1 and ordernum>"+news.ordernum+" and id<>"+newsid+(islianzai?" and mhid_list = '"+news.mhid_list+"'":"")+" order by istop,ordernum,id \
	select top 1 id,title,class_urlid from news with(nolock) where class_urlid='"+classurl+"' and status=1 and ordernum<"+news.ordernum+" and id<>"+newsid+(islianzai?" and mhid_list = '"+news.mhid_list+"'":"")+" order by istop desc,ordernum desc,id desc \
")
nextnews = Rs2Json(Rs);
Rs = Rs.NextRecordset;
prevnews = Rs2Json(Rs);

// 面包屑
if(news.mhname)
	crumb = [{url:"/"+news.mhid+"/",title:news.mhname.addEnd("漫画")},{url:"/"+news.mhid+"/"+classurl+"/",title:news.mhname+sort.name},{url:"",title:"正文"}];
else {
	crumb = [{url:"./",title:sort.name},{url:"",title:"正文"}];
	if(father.name) crumb.unshift({url:"/news/"+father.urlid+"/",title:father.name});
}
crumbshare = "本页面";


showTemplet(__config.templetpath+"news_read.shtml");

CloseRs();
CloseConn();

%>